/**
 * 
 */
package photosalvage.entity;

import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Version;

import org.hibernate.annotations.Index;

/**
 * @author shumpei
 *
 */
@Entity
@Table(name="USER_TBL")
@org.hibernate.annotations.Table(
		appliesTo="USER_TBL",
		indexes={@Index(name="IDX_USER_EMAIL",columnNames="EMAIL")})
public class User {

	@Id
	@GeneratedValue(strategy=GenerationType.SEQUENCE)
	private Long id;
	
	@Column(name="EMAIL", nullable=false, length=256, unique=true)
	private String email;
	
	@Column(name="NAME", nullable=false, length=20)
	private String name;
	
	@Column(name="PASSWORD", nullable=false, length=256)
	private String password;
	
	@Column(name="ADMINISTRATOR", nullable=false)
	private boolean administrator;
	
	@OneToMany(mappedBy="uploadedBy")
	@Column(name="UPLOADED_BY")
	private List<Photo> uploadedPhotos;
	
	@OneToMany(mappedBy="retouchedBy")
	@Column(name="RETOUCHED_BY")
	private List<Photo> retouchedPhotos;
	
	@Version
	private Long version;
	
	public Long getId() {
		return id;
	}
	public void setId(Long id) {
		this.id = id;
	}
	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public List<Photo> getUploadedPhotos() {
		return uploadedPhotos;
	}
	public void setUploadedPhotos(List<Photo> uploadedPhotos) {
		this.uploadedPhotos = uploadedPhotos;
	}
	public List<Photo> getRetouchedPhotos() {
		return retouchedPhotos;
	}
	public void setRetouchedPhotos(List<Photo> retouchedPhotos) {
		this.retouchedPhotos = retouchedPhotos;
	}
	public Long getVersion() {
		return version;
	}
	public void setVersion(Long version) {
		this.version = version;
	}
	public boolean isAdministrator() {
		return administrator;
	}
	public void setAdministrator(boolean administrator) {
		this.administrator = administrator;
	}
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		User other = (User) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}
}
